﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LMKJ.Classes;
using System.Web.Security;
using System.Collections;

namespace LMKJ
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                Response.Redirect("profile.aspx");
            }
        }

        protected void loginBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SocialWorker user = DatabaseManager.GetUserSession(usernameTbx.Text);
                Session["User"] = user;
                FormsAuthentication.RedirectFromLoginPage(usernameTbx.Text, false);
            }
        }

        protected void signupBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("register.aspx");
        }

        protected void loginValid_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string username = usernameTbx.Text;
            string password = passwordTbx.Text;

            if (DatabaseManager.Login(username, password))
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
    }
}